<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%@page import="java.sql.*,wildlife.*,java.util.*" %>
<%
String pollid=null;//=request.getParameter("pollid");
//String answer=request.getParameter("answer");
String username=session.getAttribute("username").toString();
Connect c=new Connect();
//c.dml("insert into pollresponse(pollid,options,username) values('"+pollid+"','"+answer+"','"+username+"')");
ResultSet rs1=c.getResult("select * from poll where pollid in (select pollid from pollresponse where username='"+username+"')");
while(rs1.next()){
	pollid=rs1.getString(1);
ResultSet rs=c.getResult("select count(*) from pollresponse where pollid='"+pollid+"'");
rs.next();
int total=rs.getInt(1);
//out.println(total+"");
int i=0;
HashMap<String,Integer> noofanswers=new HashMap<String,Integer>();
rs=c.getResult("select count(*),options from pollresponse where pollid='"+pollid+"' group by options");
while(rs.next()){
	noofanswers.put(rs.getString(2),rs.getInt(1));
	//out.println(noofanswers.get(i));
	//i++;
	
}
rs=c.getResult("select options,question from poll where pollid='"+pollid+"'");
rs.next();
float width=0;
String[] str=rs.getString(1).split(",");
%>
<table border="1">
<tr><td colspan="3"><%=rs.getString(2) %></td></tr>
<%
for(int j=0;j<str.length;j++)
{
	//System.out.println(str[j]);
	//out.println(noofanswers.get(str[j]));
	if(noofanswers.containsKey(str[j]))
	{
		width=(float)noofanswers.get(str[j])/total;
	width=Math.round(200*width);
	}
	else{width=0;}
	%>
	<tr><td><%=str[j] %></td><td><canvas id="myCanvas" width="<%=width %>" height="15" style="border:1px solid #c3c3c3;background-color:red">
</canvas></td><td><%= width/2+"%"%></td></tr>

<%
}%>
<tr><td colspan="3" align="center">Total no of votes:<%=total %></td></tr>
<%
}
%>
</table>
</body>
</html>